package org.aplikator.server.persistence;

import java.io.Serializable;
import java.sql.Connection;
import java.util.Date;
import java.util.List;

import org.aplikator.client.data.PrimaryKey;
import org.aplikator.client.data.Record;
import org.aplikator.client.descriptor.ViewDTO;
import org.aplikator.client.descriptor.PropertyDTO;
import org.aplikator.server.descriptor.Collection;
import org.aplikator.server.descriptor.Entity;
import org.aplikator.server.descriptor.Property;
import org.aplikator.server.descriptor.Reference;
import org.aplikator.shared.data.BinaryData;

public interface Persister {

    public Connection getJDBCConnection();

    public Transaction beginTransaction();

    public void commitTransaction(Transaction tx);

    public void close(Transaction tx);

    public String generateDDL(boolean updateDB);

    public List<Record> getPage(ViewDTO vd, PropertyDTO<Integer> ownerProperty, PrimaryKey ownerPrimaryKey, int pageOffset, int pageSize, org.aplikator.server.Context ctx);

    public int getRecordCount(ViewDTO vd, PropertyDTO<Integer> ownerProperty, PrimaryKey ownerPrimaryKey, boolean search, org.aplikator.server.Context ctx);

    public Record getRecord(ViewDTO viewDTO, PrimaryKey primaryKey, org.aplikator.server.Context ctx);

    public Record updateRecord(String entityId, Record record, Transaction tx, org.aplikator.server.Context ctx);

    public void deleteRecord(String entityId, int primaryKey, Transaction tx, org.aplikator.server.Context ctx);

    public BinaryData getBlob(Entity entity, Property<BinaryData> property, int primaryKey, int maxSize);

    public void updateBlob(Entity entity, Property<BinaryData> property, int primaryKey, String filename, byte[] data);

    public void registerEntity(Entity entity, String tableName);

    public void registerPrimaryKey(Entity entity, Property<Integer> property, String primaryKeyName);

    public void registerTimestamp(Entity entity, Property<Date> property, String timestampName);

    public <T extends Serializable> void registerProperty(Entity entity, Property<T> property, String columnName);

    public void registerReference(Entity entity, Property<Integer> property, String columnName, Entity referredEntity);

    public void registerReverseCollection(Collection<? extends Entity> many, Reference<? extends Entity> one);

    public void registerIndex(Entity entity, String name, boolean unique, Property<? extends Serializable>... properties);

    public void registerEntityClone(Entity original, Entity clone);

    public <T extends Serializable> void registerPropertyClone(Property<T> original, Property<T> clone);

}
